<template>
  <div class="app-container">

    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="订单编号" prop="docNum">
        <el-input
          v-model="queryParams.docNum"
          placeholder="请输入订单编号模糊查询"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单时间">
        <el-date-picker
          v-model="daterangeDocDt"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="交付日期">
        <el-date-picker
          v-model="daterangeOrderDeliveryDate"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="整个订单完成时间" label-width="136px">
        <el-date-picker
          v-model="daterangeDoneDt"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="订单明细物料名称" prop="orderDetailItemName" label-width="128px">
        <el-input
          v-model="queryParams.orderDetailItemName"
          placeholder="请输入订单明细物料名称模糊查询"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生产任务开始时间" label-width="136px">
        <el-date-picker
          v-model="daterangeTaskDocDt"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="生产任务单编号" prop="taskDocNum" label-width="136px">
        <el-input
          v-model="queryParams.taskDocNum"
          placeholder="请输入生产任务单编号模糊查询"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="定额时间">
        <el-date-picker
          v-model="daterangeQuotaDocDt"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="生产派工单编号" prop="taskDocNum" label-width="136px">
        <el-input
          v-model="queryParams.taskDocNum"
          placeholder="请输入生产派工单编号模糊查询"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生产派工物料名称" prop="taskItemName" label-width="136px">
        <el-input
          v-model="queryParams.taskItemName"
          placeholder="请输入生产派工物料名称模糊查询"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工序类型" prop="mesDictProcessType">
        <el-select v-model="queryParams.mesDictProcessType" placeholder="请选择工序类型" clearable size="small">
          <el-option
            v-for="dict in dict.type.mes_dict_process_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="生产派工计划开始时间" label-width="170px">
        <el-date-picker
          v-model="daterangeTaskPlanStartDt"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="生产派工实际开始时间" label-width="170px">
        <el-date-picker
          v-model="daterangeTaskStartDt"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="质检首检时间" label-width="136px">
        <el-date-picker
          v-model="daterangeFirstCheckDt"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['rpt:orderProgress:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['rpt:orderProgress:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['rpt:orderProgress:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['rpt:orderProgress:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="orderProgressList" stripe @selection-change="handleSelectionChange" :highlight-current-row="true">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="主键" align="center" prop="orderProgressUuid" />-->
      <el-table-column label="订单编号" align="center" prop="docNum" widrh="150"/>
      <el-table-column label="订单时间" align="center" prop="docDt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.docDt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="交付日期" align="center" prop="orderDeliveryDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.orderDeliveryDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="整个订单完成时间" align="center" prop="doneDt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.doneDt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单明细物料名称" align="center" prop="orderDetailItemName" width="180" :show-overflow-tooltip="true" />
      <el-table-column label="生产任务开始时间" align="center" prop="taskDocDt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.taskDocDt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="生产任务单编号" align="center" prop="taskDocNum" width="180" />
      <el-table-column label="定额时间" align="center" prop="quotaDocDt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.quotaDocDt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="生产派工单编号" align="center" prop="taskDocNum" width="180" />
      <el-table-column label="生产派工物料名称" align="center" prop="taskItemName" width="180" />
      <el-table-column label="工序类型" align="center" prop="mesDictProcessType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_dict_process_type" :value="scope.row.mesDictProcessType"/>
        </template>
      </el-table-column>
      <el-table-column label="生产派工计划开始时间" align="center" prop="taskPlanStartDt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.taskPlanStartDt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="生产派工实际开始时间" align="center" prop="taskStartDt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.taskStartDt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="质检首检时间" align="center" prop="firstCheckDt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.firstCheckDt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="120" fixed="right">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['rpt:orderProgress:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['rpt:orderProgress:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改订单进展情况对话框 -->
    <el-dialog v-dialogDrag v-dialogDragWidth :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="订单编号" prop="docNum">
          <el-input v-model="form.docNum" placeholder="请输入订单编号" />
        </el-form-item>
        <el-form-item label="订单时间" prop="docDt">
          <el-date-picker clearable size="small"
            v-model="form.docDt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择订单时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="交付日期" prop="orderDeliveryDate">
          <el-date-picker clearable size="small"
            v-model="form.orderDeliveryDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择交付日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="整个订单完成时间" prop="doneDt">
          <el-date-picker clearable size="small"
            v-model="form.doneDt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择整个订单完成时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="订单明细物料名称" prop="orderDetailItemName">
          <el-input v-model="form.orderDetailItemName" placeholder="请输入订单明细物料名称" />
        </el-form-item>
        <el-form-item label="生产任务开始时间" prop="taskDocDt">
          <el-date-picker clearable size="small"
            v-model="form.taskDocDt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择生产任务开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="生产任务单编号" prop="taskDocNum">
          <el-input v-model="form.taskDocNum" placeholder="请输入生产任务单编号" />
        </el-form-item>
        <el-form-item label="定额时间" prop="quotaDocDt">
          <el-date-picker clearable size="small"
            v-model="form.quotaDocDt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择定额时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="生产派工单编号" prop="taskDocNum">
          <el-input v-model="form.taskDocNum" placeholder="请输入生产派工单编号" />
        </el-form-item>
        <el-form-item label="生产派工物料名称" prop="taskItemName">
          <el-input v-model="form.taskItemName" placeholder="请输入生产派工物料名称" />
        </el-form-item>
        <el-form-item label="工序类型" prop="mesDictProcessType">
          <el-select v-model="form.mesDictProcessType" placeholder="请选择工序类型">
            <el-option
              v-for="dict in dict.type.mes_dict_process_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="生产派工计划开始时间" prop="taskPlanStartDt">
          <el-date-picker clearable size="small"
            v-model="form.taskPlanStartDt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择生产派工计划开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="生产派工实际开始时间" prop="taskStartDt">
          <el-date-picker clearable size="small"
            v-model="form.taskStartDt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择生产派工实际开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="质检首检时间" prop="firstCheckDt">
          <el-date-picker clearable size="small"
            v-model="form.firstCheckDt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择质检首检时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listOrderProgress, getOrderProgress, delOrderProgress, addOrderProgress, updateOrderProgress } from "@/api/rpt/orderProgress";

export default {
  name: "OrderProgress",
  dicts: ['mes_dict_process_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单进展情况表格数据
      orderProgressList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 质检首检时间时间范围
      daterangeDocDt: [],
      // 质检首检时间时间范围
      daterangeOrderDeliveryDate: [],
      // 质检首检时间时间范围
      daterangeDoneDt: [],
      // 质检首检时间时间范围
      daterangeTaskDocDt: [],
      // 质检首检时间时间范围
      daterangeQuotaDocDt: [],
      // 质检首检时间时间范围
      daterangeTaskPlanStartDt: [],
      // 质检首检时间时间范围
      daterangeTaskStartDt: [],
      // 质检首检时间时间范围
      daterangeFirstCheckDt: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        docNum: null,
        docTitle: null,
        docDt: null,
        orderDeliveryDate: null,
        doneDt: null,
        orderDetailItemName: null,
        taskDocDt: null,
        taskDocNum: null,
        quotaDocDt: null,
        taskItemName: null,
        mesDictProcessType: null,
        taskPlanStartDt: null,
        taskStartDt: null,
        firstCheckDt: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询订单进展情况列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeDocDt && '' != this.daterangeDocDt) {
        this.queryParams.params["beginDocDt"] = this.daterangeDocDt[0];
        this.queryParams.params["endDocDt"] = this.daterangeDocDt[1];
      }
      if (null != this.daterangeOrderDeliveryDate && '' != this.daterangeOrderDeliveryDate) {
        this.queryParams.params["beginOrderDeliveryDate"] = this.daterangeOrderDeliveryDate[0];
        this.queryParams.params["endOrderDeliveryDate"] = this.daterangeOrderDeliveryDate[1];
      }
      if (null != this.daterangeDoneDt && '' != this.daterangeDoneDt) {
        this.queryParams.params["beginDoneDt"] = this.daterangeDoneDt[0];
        this.queryParams.params["endDoneDt"] = this.daterangeDoneDt[1];
      }
      if (null != this.daterangeTaskDocDt && '' != this.daterangeTaskDocDt) {
        this.queryParams.params["beginTaskDocDt"] = this.daterangeTaskDocDt[0];
        this.queryParams.params["endTaskDocDt"] = this.daterangeTaskDocDt[1];
      }
      if (null != this.daterangeQuotaDocDt && '' != this.daterangeQuotaDocDt) {
        this.queryParams.params["beginQuotaDocDt"] = this.daterangeQuotaDocDt[0];
        this.queryParams.params["endQuotaDocDt"] = this.daterangeQuotaDocDt[1];
      }
      if (null != this.daterangeTaskPlanStartDt && '' != this.daterangeTaskPlanStartDt) {
        this.queryParams.params["beginTaskPlanStartDt"] = this.daterangeTaskPlanStartDt[0];
        this.queryParams.params["endTaskPlanStartDt"] = this.daterangeTaskPlanStartDt[1];
      }
      if (null != this.daterangeTaskStartDt && '' != this.daterangeTaskStartDt) {
        this.queryParams.params["beginTaskStartDt"] = this.daterangeTaskStartDt[0];
        this.queryParams.params["endTaskStartDt"] = this.daterangeTaskStartDt[1];
      }
      if (null != this.daterangeFirstCheckDt && '' != this.daterangeFirstCheckDt) {
        this.queryParams.params["beginFirstCheckDt"] = this.daterangeFirstCheckDt[0];
        this.queryParams.params["endFirstCheckDt"] = this.daterangeFirstCheckDt[1];
      }
      listOrderProgress(this.queryParams).then(response => {
        this.orderProgressList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        orderProgressUuid: null,
        docNum: null,
        docTitle: null,
        docDt: null,
        orderDeliveryDate: null,
        doneDt: null,
        orderDetailItemName: null,
        taskDocDt: null,
        quotaDocDt: null,
        taskDocNum: null,
        taskItemName: null,
        mesDictProcessType: null,
        taskPlanStartDt: null,
        taskStartDt: null,
        firstCheckDt: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeDocDt = [];
      this.daterangeOrderDeliveryDate = [];
      this.daterangeDoneDt = [];
      this.daterangeTaskDocDt = [];
      this.daterangeQuotaDocDt = [];
      this.daterangeTaskPlanStartDt = [];
      this.daterangeTaskStartDt = [];
      this.daterangeFirstCheckDt = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.orderProgressUuid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加订单进展情况";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const orderProgressUuid = row.orderProgressUuid || this.ids
      getOrderProgress(orderProgressUuid).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改订单进展情况";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.orderProgressUuid != null) {
            updateOrderProgress(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrderProgress(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const orderProgressUuids = row.orderProgressUuid || this.ids;
      this.$modal.confirm('是否确认删除订单进展情况编号为"' + orderProgressUuids + '"的数据项？').then(function() {
        return delOrderProgress(orderProgressUuids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('rpt/orderProgress/export', {
        ...this.queryParams
      }, `rpt_orderProgress.xlsx`)
    }
  }
};
</script>
